package com.liyu.iblog.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.liyu.iblog.dao.BlogDao;
import com.liyu.iblog.domain.Blog;

@Service("homeService")
public class HomeServiceImpl implements HomeService {

    private BlogDao blogDao;
    
    @Autowired
    public HomeServiceImpl(BlogDao blogDao) {
        this.blogDao = blogDao;
    }
    
    /**
     * gather information for the home page
     */
    @Override
    public Map<String, Object> gatherInfoForHomePage() {
        Map<String, Object> infoMap = new HashMap<String, Object>();
        //load latest 5 blogs
        List<Blog> latestBlogs = blogDao.getBlogsWithTimeDescOrder(0, 5, BlogService.DEFAULT_BLOG_OWNER);
        infoMap.put("blogs", latestBlogs);
        return infoMap;
    }

}
